jQuery.extend({
    upload: function(url, params, callback) {

        var id = "media:" + (new Date().valueOf()).toString();
        var uploading = false;
        $("<iframe class='ifm_upload_media' id='" + id + "' name='" + id + "' src='about:blank'></iframe>")
         .load(function() {
             if (uploading == false) {
                 uploading = true;
                 var ifmUpload = $(this).contents().find("body");

                 if (jQuery.browser.msie) {
                     var uploadForm = $('<form class="hide" action="' + url + '" enctype="multipart/form-data" method="post"></form>');

                     $.each(params, function(name, value) {
                         if (typeof value == "object" && value.tagName != "") {
                             uploadForm.append($(value).after($(value).clone().get(0)).attr("name", name).get(0));
                         }
                         else
                             uploadForm.append($('<input type="text" />').attr("name", name).attr("value", value).get(0));
                     });

                     uploadForm.appendTo("body").submit();
                 } else {
                     $('<form action="' + url + '" enctype="multipart/form-data" method="post"><input type="submit" /></form>')
                        .appendTo(ifmUpload);

                     $.each(params, function(name, value) {
                         if (typeof value == "object" && value.tagName != "") {
                             $("form", ifmUpload).append($(value).after($(value).clone().get(0)).attr("name", name).get(0));
                         }
                         else
                             $("form", ifmUpload).append($('<input type="text" />').attr("name", name).attr("value", value).get(0));
                     });

                     $(":submit", ifmUpload).click();
                 }
             } else {
                 var data = $.trim($.browser.msie ? $($(this).contents().text()).text() : $(this).contents().text());
                 callback(data);
                 $(this).hide();
             }
         })
         .appendTo("body");
    }
});